package com.easyn.P2PCam264;

import java.util.ArrayList;

import com.easyn.CamLinePro.R;
import com.easyn.CamLinePro.R.layout;
import com.easyn.CamLinePro.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class UserManual extends Activity {

	private ViewPager mViewPager;
	private ImageView mPage0;
	private ImageView mPage1;
	private ImageView mPage2;
	private ImageView mPage3;
	private int currIndex = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_user_manual);
		
		mViewPager = (ViewPager)findViewById(R.id.whatsnew_viewpager);        
        mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
       
        
        mPage0 = (ImageView)findViewById(R.id.page0);
        mPage1 = (ImageView)findViewById(R.id.page1);
        mPage2 = (ImageView)findViewById(R.id.page2);
        mPage3 = (ImageView)findViewById(R.id.page3);
        
      //将要分页显示的View装入数组中
        LayoutInflater mLi = LayoutInflater.from(this);
        
        String ev = getResources().getConfiguration().locale.getCountry();
        
        View view1,view2,view3,view4;
        
        if(ev.equals("CN")){
            view1 = mLi.inflate(R.layout.whats1, null);
            view2 = mLi.inflate(R.layout.whats2, null);
            view3 = mLi.inflate(R.layout.whats3, null);
            view4 = mLi.inflate(R.layout.whats4, null);        	
        }else if(ev.equals("TW")){
            view1 = mLi.inflate(R.layout.whats9, null);
            view2 = mLi.inflate(R.layout.whats10, null);
            view3 = mLi.inflate(R.layout.whats11, null);
            view4 = mLi.inflate(R.layout.whats12, null);
        }else if(ev.equals("KR")){
            view1 = mLi.inflate(R.layout.whats13, null);
            view2 = mLi.inflate(R.layout.whats14, null);
            view3 = mLi.inflate(R.layout.whats15, null);
            view4 = mLi.inflate(R.layout.whats16, null);
        }else if(ev.equals("RU")){
            view1 = mLi.inflate(R.layout.whats17, null);
            view2 = mLi.inflate(R.layout.whats18, null);
            view3 = mLi.inflate(R.layout.whats19, null);
            view4 = mLi.inflate(R.layout.whats20, null);
        }else if(ev.equals("ES")){
            view1 = mLi.inflate(R.layout.whats21, null);
            view2 = mLi.inflate(R.layout.whats22, null);
            view3 = mLi.inflate(R.layout.whats23, null);
            view4 = mLi.inflate(R.layout.whats24, null);
        }else{
            view1 = mLi.inflate(R.layout.whats5, null);
            view2 = mLi.inflate(R.layout.whats6, null);
            view3 = mLi.inflate(R.layout.whats7, null);
            view4 = mLi.inflate(R.layout.whats8, null);        	        	
        }
        
      //每个页面的view数据
        final ArrayList<View> views = new ArrayList<View>();
        views.add(view1);
        views.add(view2);
        views.add(view3);
        views.add(view4);
        
        //填充ViewPager的数据适配器
        PagerAdapter mPagerAdapter = new PagerAdapter() {
			
			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				return arg0 == arg1;
			}
			
			@Override
			public int getCount() {
				return views.size();
			}

			@Override
			public void destroyItem(View container, int position, Object object) {
				((ViewPager)container).removeView(views.get(position));
			}
			
			
			
			@Override
			public Object instantiateItem(View container, int position) {
				((ViewPager)container).addView(views.get(position));
				return views.get(position);
			}
		};
		
		mViewPager.setAdapter(mPagerAdapter);
	}
	
	 public class MyOnPageChangeListener implements OnPageChangeListener {
			@Override
			public void onPageSelected(int arg0) {
				switch (arg0) {
				case 0:				
					mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
					mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
					break;
				case 1:
					mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
					mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
					mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
					break;
				case 2:
					mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
					mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
					mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page));
					break;
				case 3:
					mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
					mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
					break;
				}
				currIndex = arg0;
				//animation.setFillAfter(true);// True:图片停在动画结束位置
				//animation.setDuration(300);
				//mPageImg.startAnimation(animation);
			}
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		}
	 
	 public void onExit(View v){
		 finish();
	 }

}
